<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

class ChatroomRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $editRules = [
            'name'        => 'required',
            'description' => 'required',
            'maxusers'    => 'required|numeric',
            'type'        => 'required',
            'uid'         => 'required|numeric',
            'activity_id' => 'required|numeric',
        ];

        $createRules = [
            'name'        => 'required',
            'description' => 'required',
            'maxusers'    => 'required|numeric',
            'type'        => 'required',
            'uid'         => 'required|numeric',
            'activity_id' => 'required|numeric',
        ];

//        return array();

        $data = Request::all();
        //如果是编辑
        if ($data['formType'] == 'edit') {
            return $editRules;
        }
        //如果是创建
        if ($data['formType'] == 'create') {
            return $createRules;
        }
    }

    public function attributes()
    {
        $attributes = array(
            'name'        => '名称',
            'description' => '描述',
            'maxuser'     => '人数上限',
            'type'        => '类型',
            'uid'         => '真实的管理员',
            'activity_id' => '关联的活动',
        );

        return $attributes;
    }

    public function messages()
    {
        $messages = [
            'required' => ':attribute为必填选项',
            'numeric'  => ':attribute必须为数字',
        ];

        return $messages;
    }
}
